package com.learning.servlet2x.skip;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * ClassName: ForwardServlet
 * Description: 转发 Servlet
 * Date: 2018/6/23 14:11 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class ForwardServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        PrintWriter writer = resp.getWriter();
        writer.write("在 Forward 之前不能向客户端输出结果");
        writer.flush();

        req.setAttribute("param", "request_param");

        // 跳转到文件下载的 Servlet
        // RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/downloadServlet")
        RequestDispatcher dispatcher = req.getRequestDispatcher("/requestServlet");
        dispatcher.forward(req, resp);
    }
}
